package com.rshare.cloud.rspub.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

import org.apache.commons.lang3.StringUtils;

public class StringEnhanceUtils {

	public static String lpad(int length, long number) {
		String f = "%0" + length + "d";
		return String.format(f, number);
	}

	/**
	 * 获得20位流水号 
	 * 前四位前缀(必须为四位)
	 * 中间6位为月份
	 * 10位顺序数
	 * @param type
	 * @return
	 */
	public static String get20SerialNumber(String type) {
		if(StringUtils.isBlank(type)||type.length()!=4)
		{
			return null;
		}
		Random rn=new Random();	
		int seqence=rn.nextInt(99999999);
		String serialNum = "";
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		String qz = type + sf.format(cal.getTime());
//		long lsm = this.getYwxh(type, qz);
		serialNum = qz + StringEnhanceUtils.lpad(8, seqence);
		return serialNum;
	}
	
	/**
	 * main函数.
	 * @param args
	 *            启动参数
	 * @throws Exception
	 *             Exception
	 */
	public static void main(String... args) throws Exception
	{
		for(int i=0;i<10;i++)
		System.out.println(StringEnhanceUtils.get20SerialNumber("ZCXF"));
	}

}
